<template>
  <el-dialog
      title="提示"
      v-model="dialogVisible"
      width="50%"
      append-to-body
      :before-close="handleClose">
    <avue-form ref="form" v-model="formModel" @submit="submitForm" :option="formOption">
      <template slot="menuForm">
        <el-button @click="dialogVisible=false">取消</el-button>
      </template>
    </avue-form>
    <start-act-dialog ref="startActDialog" @close="handleClose()" @submitSuccess="actStartSuccess"></start-act-dialog>
  </el-dialog>
</template>

<script>
import userOption from "@/option/sys/userOption";
import actModelOption from "@/option/start/activiti/actModelOption";
import userApi from "@/api/sys/userApi";
import optionUtils from "@/option/optionUtils";
import actModelApi from "@/api/start/activiti/actModelApi";
import StartActDialog from "../components/startActDialog.vue";
import startActModelApi from "@/api/start/activiti/core/startActModelApi";

const modelOption = actModelOption();
export default {
  name: "startConfigDialog",
  components: {StartActDialog},
  computed: {
    formOption() {
      return {
        submitText: "确定",
        column: [
          {
            label: '流程',
            span: 24,
            prop: 'modelKey',
            type: "table",
            props: {
              label: 'modelName',
              value: 'modelKey'
            },
            children: modelOption,
            onLoad: (onLoadParams, callback) => {
              onLoadParams.pageDefinition = startActModelApi.pageDeployActModel
              onLoadParams.valueDefinition = actModelApi.getById
              onLoadParams.option = modelOption;
              optionUtils.tableOnLoad(onLoadParams, callback)
            },
          },
          {
            label: '启动人',
            span: 24,
            prop: 'userId',
            type: "table",
            props: {
              label: 'userFinalName',
              value: 'id'
            },
            row: true,
            children: userOption(),
            onLoad: (onLoadParams, callback) => {
              onLoadParams.pageDefinition = userApi.list
              onLoadParams.valueDefinition = userApi.getUserInfo
              onLoadParams.option = userOption;
              optionUtils.tableOnLoad(onLoadParams, callback)
            },
            formatter: (row) => {
              if (!row) return;
              if (row.nickName) {
                return row.nickName;
              } else if (row.realName) {
                return row.realName
              }
              return row.userName;
            }
          },
        ]
      }
    }
  },
  data() {
    return {
      dialogVisible: false,
      formModel: {}
    }
  },
  methods: {
    show() {
      this.dialogVisible = true
    },
    handleEmpty() {

    },
    handleClose() {
      this.dialogVisible = false
      this.handleEmpty();
    },
    submitForm(model, done) {
      done();
      this.$refs.startActDialog.show(model)
    },
    actStartSuccess() {
      this.$emit("refresh");
    }
  }
}
</script>

<style scoped>

</style>
